document.addEventListener('DOMContentLoaded', function() {
    // 获取DOM元素
    const typeButtons = document.querySelectorAll('.type-btn');
    const textSearch = document.getElementById('text-search');
    const fileUpload = document.getElementById('file-upload');
    const fileInput = document.getElementById('file-input');
    const resultsContainer = document.getElementById('results-container');

    // 切换搜索类型
    typeButtons.forEach(button => {
        button.addEventListener('click', () => {
            // 移除所有按钮的active类
            typeButtons.forEach(btn => btn.classList.remove('active'));
            // 添加当前按钮的active类
            button.classList.add('active');
            
            // 根据类型显示对应的搜索输入方式
            const type = button.dataset.type;
            if (type === 'text') {
                textSearch.style.display = 'flex';
                fileUpload.style.display = 'none';
            } else {
                textSearch.style.display = 'none';
                fileUpload.style.display = 'block';
                
                // 更新文件接受类型
                switch(type) {
                    case 'image':
                        fileInput.accept = 'image/*';
                        break;
                    case 'audio':
                        fileInput.accept = 'audio/*';
                        break;
                    case 'video':
                        fileInput.accept = 'video/*';
                        break;
                }
            }
        });
    });

    // 文件拖拽上传
    const dropZone = document.querySelector('.file-upload');
    
    dropZone.addEventListener('dragover', (e) => {
        e.preventDefault();
        dropZone.style.borderColor = '#007bff';
    });

    dropZone.addEventListener('dragleave', () => {
        dropZone.style.borderColor = '#ddd';
    });

    dropZone.addEventListener('drop', (e) => {
        e.preventDefault();
        dropZone.style.borderColor = '#ddd';
        const files = e.dataTransfer.files;
        if (files.length) {
            fileInput.files = files;
            handleFileUpload(files[0]);
        }
    });

    // 文件选择处理
    fileInput.addEventListener('change', (e) => {
        if (e.target.files.length) {
            handleFileUpload(e.target.files[0]);
        }
    });

    // 文件上传处理函数
    function handleFileUpload(file) {
        // 这里添加文件预览逻辑
        const reader = new FileReader();
        reader.onload = function(e) {
            // 可以在这里添加预览图片或其他预览逻辑
            console.log('File loaded:', file.name);
        }
        reader.readAsDataURL(file);
    }

    // 搜索按钮点击事件
    document.querySelectorAll('.search-btn').forEach(btn => {
        btn.addEventListener('click', () => {
            // 这里添加搜索逻辑
            console.log('Searching...');
            // 模拟搜索结果
            showDummyResults();
        });
    });

    // 模拟展示搜索结果
    function showDummyResults() {
        resultsContainer.innerHTML = ''; // 清空现有结果
        
        // 添加示例结果
        for (let i = 0; i < 8; i++) {
            const resultItem = document.createElement('div');
            resultItem.className = 'result-item';
            resultItem.innerHTML = `
                <img src="https://via.placeholder.com/200x150" alt="结果${i + 1}">
                <p>搜索结果 ${i + 1}</p>
            `;
            resultsContainer.appendChild(resultItem);
        }
    }
}); 